// pages/addLesson/addLesson.js
var common = require("../../utils/util.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    lessonName:'',
      info:{
          mobile: '',
          code: '',
          exhid:'',
          openid:'',
          name: ''
      },
      time:'获取验证码'
  },
  /**
   * 生命周期函数--监听页面加载
   */
  send_code: function() {
      if (this.data.time > 0) {
          return false
      }
      console.log(this.data.info.mobile)
      if (!common.is_mobile(this.data.info.mobile)) {
          wx.showToast({
              title: '请输入正确的手机号',
              icon: 'none'
          })
      } else {
          var that = this
          common.bapiajax({
              url: 'GetVerificationCode',
              data: {
                  mobile: this.data.info.mobile
              },
              loading: '发送中...',
              success: function (res) {
                  if (res.status == 'SUCCESS') {
                      that.setData({
                          time: 60
                      })
                      var timer = setInterval(function () {
                          that.data.time--
                          if (that.data.time == 0) {
                              clearInterval(timer)
                          }
                          that.setData({
                              time: that.data.time
                          })
                      }, 1000)
                  } else {
                      common.info(res.result.msg)
                  }
              },
              fail: function () {
                  common.info('发送失败，请重试')
              }
          })
      }
  },
  onLoad: function (options) {
      wx.setNavigationBarTitle({
          title: '无名片登记'
      });
  },
    bindname:function (e) {
        var name = 'info.name'
        var that = this;
        that.setData({
           [name]:e.detail.value
        })
    },
    bindphone:function (e) {
        var phone = 'info.mobile'
        var that = this;
        that.setData({
            [phone]:e.detail.value
        })
        console.log(that.data.info.mobile)
    },
    bindcode:function () {
        var code = 'info.code'
        var that = this;
        that.setData({
            [code]:e.detail.value
        })
    },
    next:function () {
    var that= this;
    if (that.data.info.name == '') {
      common.info('请输入姓名')
        return false
    }
    if (that.data.info.mobile == '') {
        common.info('请输入手机号')
        return false
    }
    if (common.is_mobile(that.data.info.mobile)) {
        common.info('请输入正确的手机号')
        return false
    }
    wx.navigateTo({
        url:'../registration/registration'
    })
    },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})